﻿using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _009_LINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            var masterList = new List<MartialArtsMaster>()
            {
                new MartialArtsMaster() {Id = 1, Name = "黄蓉", Age = 18, Menpai = "丐帮", Kongfu = "打狗棍法", Level = 9},
                new MartialArtsMaster() {Id = 2, Name = "洪七公", Age = 70, Menpai = "丐帮", Kongfu = "葵花宝典", Level = 7},
                new MartialArtsMaster() {Id = 3, Name = "任我行", Age = 23, Menpai = "丐帮", Kongfu = "葵花宝典", Level = 8},
                new MartialArtsMaster() {Id = 4, Name = "东方不败", Age = 45, Menpai = "明教", Kongfu = "打狗棍法", Level = 10},
                new MartialArtsMaster() {Id = 5, Name = "林平之", Age = 18, Menpai = "明教", Kongfu = "无痕剑意", Level = 10},
                new MartialArtsMaster() {Id = 6, Name = "岳不群", Age = 65, Menpai = "明教", Kongfu = "九阴真经", Level = 9},
                new MartialArtsMaster() {Id = 7, Name = "令狐冲", Age = 65, Menpai = "华山", Kongfu = "独孤九剑", Level = 8},
                new MartialArtsMaster() {Id = 8, Name = "梅超风", Age = 23, Menpai = "华山", Kongfu = "弹指神功", Level = 6},
                new MartialArtsMaster() {Id = 9, Name = "郭靖", Age = 45, Menpai = "桃花岛", Kongfu = "降龙十八掌", Level = 7},
                new MartialArtsMaster() {Id = 10, Name = "黄药师", Age = 77, Menpai = "桃花岛", Kongfu = "打狗棍法", Level = 9},
            };

            var kongfuList = new List<Kongfu>()
            {
                new Kongfu() {Id = 1, Name = "打狗棍法", Power = 90},
                new Kongfu() {Id = 2, Name = "葵花宝典", Power = 96},
                new Kongfu() {Id = 3, Name = "无痕剑意", Power = 100},
                new Kongfu() {Id = 4, Name = "九阴真经", Power = 90},
                new Kongfu() {Id = 5, Name = "独孤九剑", Power = 95},
                new Kongfu() {Id = 6, Name = "弹指神功", Power = 85},
                new Kongfu() {Id = 7, Name = "降龙十八掌", Power = 100},
            };

            // 查询所有武学级别大于8的宗师
            //            var res = from m in masterList
            //                from k in kongfuList
            //                      where m.Kongfu == k.Name && k.Power>90
            //                select new {master = m,kongfu = k};

            //            var res = masterList.SelectMany(k => kongfuList, (m, k) => new {master = m, kongfu = k}).Where(x =>
            //                x.master.Kongfu == x.kongfu.Name && x.kongfu.Power> 90);

            //            var res = from m in masterList
            //                where m.Level > 6 && m.Menpai == "丐帮"
            //                orderby m.Age,m.Level
            //                select m;

            //            var res = masterList.Where(m => m.Level > 6).OrderBy(r => r.Age).ThenByDescending(r => r.Level);

            //            var res = from m in masterList
            //                join k in kongfuList on m.Kongfu equals k.Name
            //                select new {master = m, kongfu = k};

            //            var res = from k in kongfuList
            //                join m in masterList on k.Name equals m.Kongfu
            //                    into groups
            //                orderby groups.Count()
            //                select new {kongfu = k, count = groups.Count()};

//            var res = from m in masterList
//                group m by m.Menpai
//                into g
//                select new {count = g.Count(), key = g.Key};	//	g.Key Key表示是按照哪个属性分的组
            masterList.Any(m => m.Menpai == "丐帮");
            foreach (var temp in res)
            {
                Console.WriteLine(temp);
            }

            Console.ReadKey();
        }


    }
}
